package com.buglife.video.convert.service.imp;

import org.springframework.stereotype.Service;

import com.buglife.video.convert.service.IVideoConvertService;
import com.buglife.video.convert.util.Conversor;
import com.xuggle.mediatool.IMediaReader;
import com.xuggle.mediatool.IMediaWriter;
import com.xuggle.mediatool.ToolFactory;

@Service
public class VideoConvertService implements IVideoConvertService{

    @Override
    public void convert(String input, String output) {
        Conversor conversor = new Conversor();
        IMediaReader reader = ToolFactory.makeReader(input);
        reader.addListener(conversor);
        IMediaWriter writer = ToolFactory.makeWriter(output, reader);
        int channelCount = 2;
        int sampleRate = 44100;
        writer.addAudioStream(1, 0, channelCount, sampleRate);
        writer.addVideoStream(0, 0, VIDEO_WIDTH, VIDEO_HEIGHT);
        conversor.addListener(writer);
        while ( reader.readPacket() == null) {
        //do nothing
        }
    }
    
    public static void main(String[] args) {
        new VideoConvertService().convert("C:\\VideoConvert\\VID_20141004_171836.mp4", "C:\\VideoConvert\\test.flv");
    }
    
}
